package com.base.cn.platform.os.service.course.open;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.dao.course.open.CourseOpenBespeakDao;
import com.base.cn.platform.os.entity.course.open.CourseOpen;
import com.base.cn.platform.os.entity.course.open.CourseOpenBespeak;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * 免费直播预约记录Biz
 *
 * @author s.li
 * @create 2018-09-11-16:18
 */
@Service
public class CourseOpenBespeakBiz extends BaseBiz<CourseOpenBespeak,CourseOpenBespeakDao> {

    @Autowired
    private CourseOpenBiz courseOpenBiz;

    /**
     * 获取用户的免费直播预约记录
     * @param userId 用户ID
     * @param openCourseId 免费直播ID
     * @return CourseOpenBespeak
     */
    public CourseOpenBespeak getUserCourseOpenBespeak(BigDecimal userId,BigDecimal openCourseId){
        CourseOpenBespeak _courseOpenBespeak = this.findOne(" userId="+ userId +" and openCourseId="+ openCourseId,null);
        return _courseOpenBespeak;
    }

    /**
     * 保存预约记录
     * @param courseOpenBespeak 数据对象
     * @return CourseOpenBespeak
     */
    @Transactional(rollbackFor = IllegalArgumentException.class)
    public CourseOpenBespeak saveBespeak(CourseOpenBespeak courseOpenBespeak,CourseOpen courseOpen){
        courseOpenBespeak.setBespeak(1);
        this.save(courseOpenBespeak);
        courseOpen.setBespeakNum(courseOpen.getBespeakNum().intValue() +1);
        courseOpen.setPlayUrl(null);
        courseOpen.setDomainName(null);
        courseOpen.setLiveAccount(null);
        courseOpenBiz.updateById(courseOpen,null);
        return courseOpenBespeak;
    }
}
